λ¬Έμ
Programmers - nμ§μ κ²μ
π Logic
while (idx != t) {
String strNum = Integer.toString(num, n);
for (int i = 0; i < strNum.length() && idx != t; i++) {
if (order == p) answer[idx++] = String.valueOf(strNum.charAt(i)).toUpperCase();
order++;
if (order == m + 1) order = 1;
}
num++;
}
strNum μ 0λΆν° 1μ© μ¦κ°νλ μλ₯Ό μ£Όμ΄μ§ n μ§λ²μ λ°λΌ λ³νν λ¬Έμμ΄μ΄λ€.
- ν΄λΉ λ¬Έμμ΄μ κ° λ¨μ΄λ₯Ό νμνλλ°, μ΄λ
order κ° p μ λμΌνλ€λ©΄, μ¦ νλΈμ μμκ° λμλ€λ©΄ ν΄λΉ λ¨μ΄λ₯Ό answer μ μΆκ°νλ€.
π CODE
μ½λ 보기/μ κΈ°π«
import java.util.*;
class Solution {
public String solution(int n, int t, int m, int p) {
String[] answer = new String[t];
int num = 0;
int idx = 0;
int order = 1;
while (idx != t) {
String strNum = Integer.toString(num, n);
for (int i = 0; i < strNum.length() && idx != t; i++) {
if (order == p) answer[idx++] = String.valueOf(strNum.charAt(i)).toUpperCase();
order++;
if (order == m + 1) order = 1;
}
num++;
}
return String.join("", answer);
}
}
βοΈ Review
- κ°λ¨ν λ¬Έμ μλ€.
- μ²μμλ nμ§μλ₯Ό μΌμΌμ΄ ꡬνλ λ°©λ²μ ꡬννλλ°,
Integer.toString(int n, int radix) λ©μλλ‘ μ½κ² nμ§μλ₯Ό ꡬν μ μμ΄ μ΄λ₯Ό μ μ©νλ€.